 package me.freesoft.distributioin;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.apache.poi.xssf.usermodel.XSSFWorkbook;

public class demo {

	
	public static void main(String[] args) throws Exception {

		List pe = new ArrayList();
		List pb = new ArrayList();
		int i = 0;
		String s ="";
		String t ="";  
		ReadExcelUtil readExcelUtil = new ReadExcelUtil("C:/Users/lenovo/Desktop/指数温度计算/中证500/pe-pb.xlsx"); // 读取excel
		Map<Integer, Map<Integer, Object>> map = readExcelUtil.readExcelContent();
		
		for (int j = 1; j <= map.size(); j++) {
			pe.add(Double.parseDouble((map.get(j).get(1)) + ""));
			pb.add(Double.parseDouble((map.get(j).get(3)) + ""));
			if (i > 0) {
				double p1 = Distributioin.distriValue(Double.parseDouble((map.get(j).get(1)) + ""), pe); // pe
				double d1 = Distributioin.distriValue(Double.parseDouble((map.get(j).get(3)) + ""), pb); // pb
				map.get(j).put(2, p1);
				map.get(j).put(4, d1);
				map.get(j).put(5, InsUtil.ins((p1 + d1) / 2)); // 指数温度
			
				
			}
			i++;
			//System.out.println(map.get(j).toString());
			s+=",'"+map.get(j).get(0)+"'";
			t+=","+map.get(j).get(5)+"";
			
		}
		
		System.out.println("s:"+s);
		System.out.println("t:"+t);

		// 生成excel文件
		ArrayList<String[]> content = new ArrayList<String[]>();
		String[] titleArrayName = { "时间", "PE", "PE温度", "PB", "PB温度", "指数温度" }; // 表头
		content.add(titleArrayName);

		for (int j = 1; j <= map.size(); j++) {
			String[] contentArray = { map.get(j).get(0) + "", map.get(j).get(1) + "", map.get(j).get(2) + "",
					map.get(j).get(3) + "", map.get(j).get(4) + "", map.get(j).get(5) + ""

			};
			content.add(contentArray);
		}

		try {
			ExportExcelUtil eu = new ExportExcelUtil().exprotExecl(content, null);

			XSSFWorkbook wb = eu.wb;

			File f = new File("C:/Users/lenovo/Desktop/指数温度计算/中证500/中证500.xlsx"); // 生产excel文件 ,全路径
			if (!f.exists()) {
				f.getParentFile().mkdir();
				try {
					// 创建文件
					f.createNewFile();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			FileOutputStream os = new FileOutputStream(f);
			wb.write(os);

			os.close();
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}
